﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public abstract class Button:IGameElement
    {
        private IAction buttonAction;
        private Button previousButton, nextButton;
        private KeyCode k;
        private bool isActive;
        private Point2D buttonPos;

        public Point2D ButtonPos
        {
            get { return buttonPos; }
            set { buttonPos = value; }
        }

        public bool IsActive
        {
            get { return isActive; }
            set { isActive = value; }
        }

        public KeyCode K
        {
            get { return k; }
        }

        public IAction ButtonAction
        {
            get { return buttonAction; }
            set { buttonAction = value; }
        }

        public Button(KeyCode k, bool isActive, int buttonPosX, int buttonPosY)
        {
            this.k = k;
            this.isActive = isActive;
            this.buttonPos.X = buttonPosX;
            this.buttonPos.Y = buttonPosY;
        }
        
        public Button NextButton
        {
            get { return nextButton; }
            set { nextButton = value; }
        }

        public Button PreviousButton
        {
            get { return previousButton; }
            set { previousButton = value; }
        }

        public void Update(GameController gc)
        {
            buttonAction.DoAction(gc);
        }

        public abstract void Draw();

        public void ChangeSelectedButton()
        {
            if (!Input.KeyTyped(KeyCode.vk_UP) && !Input.KeyTyped(KeyCode.vk_DOWN)) return;

            if (Input.KeyTyped(KeyCode.vk_UP) && PreviousButton != null)
            {
                this.IsActive = false;
                PreviousButton.IsActive = true;
            }
            else if (Input.KeyTyped(KeyCode.vk_DOWN) && NextButton != null)
            {
                this.IsActive = false;
                NextButton.IsActive = true;
            }
        }
    }
}
